//验证标识
var pwFlag = false;
/**
 * 密码输入验证
 */
function testInput(){
	var v1 = document.getElementById("new_password").value;
	var v2 = document.getElementById("tblUser.password").value;
	var v3 = document.getElementById("Prompt");
	var reg = new RegExp(/^[A-Za-z]+[0-9]+[A-Za-z0-9]*|[0-9]+[A-Za-z]+[A-Za-z0-9]*$/g);
	if(v1==''&&v2!=''){
		v3.innerHTML="输入框内容不能为空！";
		return;
	}else{
		if(v1==''){
			pwFlag=false;
			return;
		}else{
			if(!reg.test(v1)){
				v3.innerHTML="密码必须由6-16个英文字母和数字字符串组成！";
				pwFlag=false;
			}else{
				v3.innerHTML="";
				if(v2!=''){
					if(v1.localeCompare(v2)==0){
						pwFlag = true;
						return;
					}else{
						v3.innerHTML="两次输入信息不一致！";
						pwFlag=false;
						return;
					}
				}
			}
		}
	}
}
/**
 * 确认提交修改
 * @returns {Boolean}
 */
function changePwAction(){
	var v3 = document.getElementById("Prompt");
	var un = document.getElementById("tblUser.username").value;
	var pw = document.getElementById("tblUser.password").value;
	if(pwFlag){
		$.ajax({
			url:'user_update',
			type:'post',
			data:'tblUser.username='+un+'&tblUser.password='+pw,
			success:function(){
				v3.style.color="green";
				v3.innerHTML="密码修改成功！";
			},
			error:function(){
				v3.style.color="red";
				v3.innerHTML="执行失败！";
			}
		});
	}else{
		v3.style.color="red";
		v3.innerHTML="数据不合法，请仔细检查。";
		return false;
	}
	
}
/**
 * 显示/隐藏
 */
function showPwMsg(){
	var pw = document.getElementById("myPw");
	if(pw.type=='password'){
		pw.type='text';
	}else{
		pw.type='password';
	}
}
/**
 * 显示/隐藏
 */
function checkmsg(){
	var btn0 = document.getElementById("check_msg");
	var btn2 = document.getElementById("new_password");
	var btn3 = document.getElementById("tblUser.password");
	if(btn3.type=='password'){
		btn2.type = 'text';
		btn3.type = 'text';
		btn0.value = "隐藏密码";
	}else{
		btn2.type = 'password';
		btn3.type = 'password';
		btn0.value = '查看密码';
	}
}
/**
 * 密码修改弹出窗
 */
window.onload = function (){
	var oWin = document.getElementById("win"); 
	var oLay = document.getElementById("overlay"); 
	var oBtn = document.getElementById("b_thrid");
	var oClose = document.getElementById("close"); 
	var oH2 = oWin.getElementsByTagName("h2")[0]; 
	var bDrag = false; 
	var disX = disY = 0; 
	oBtn.onclick = function () { 
		oLay.style.display = "block"; 
		oWin.style.display = "block";
	}; 
	oClose.onclick = function () { 
		oLay.style.display = "none"; 
		oWin.style.display = "none";
	}; 
	oClose.onmousedown = function (event) { 
		(event || window.event).cancelBubble = true; 
	}; 
	oH2.onmousedown = function (event) { 
		var event = event || window.event; 
		bDrag = true; 
		disX = event.clientX - oWin.offsetLeft; 
		disY = event.clientY - oWin.offsetTop; 
		this.setCapture && this.setCapture(); 
		return false;
	};
	document.onmousemove = function (event) {
		if (!bDrag) {
			return;
		}
		var event = event || window.event; 
		var iL = event.clientX - disX; 
		var iT = event.clientY - disY; 
		var maxL = document.documentElement.clientWidth - oWin.offsetWidth; 
		var maxT = document.documentElement.clientHeight - oWin.offsetHeight; 
		iL = iL < 0 ? 0 : iL; 
		iL = iL > maxL ? maxL : iL; 
		iT = iT < 0 ? 0 : iT; 
		iT = iT > maxT ? maxT : iT; 
			
		oWin.style.marginTop = oWin.style.marginLeft = 0; 
		oWin.style.left = iL + "px"; 
		oWin.style.top = iT + "px"; 
		return false;
	}; 
	document.onmouseup = window.onblur = oH2.onlosecapture = function () { 
		bDrag = false; 
		oH2.releaseCapture && oH2.releaseCapture(); 
	}; 
};